
/************************************************************************
* Array implemented as a Queue
* GSP295 Week2 iLab: FIFO Queue
* Author: Ronald Ram
************************************************************************/



#include <iostream>
#include "QueueArray.h"

using namespace std;
using namespace GSP295_Wk2;


void WelcomeMsg();
void AddToQueue();
void RemoveFromQueue();
void ClearQueue();
void PrintQueue();
void Instructions();
void Command(char input);



char yesNo, addRemoveClearPrint;
bool quit = false, bAddRemoveClearPrintQuit = false;
string input, output;

QueueArray *queue;


int main()
{
	queue = new QueueArray();
	WelcomeMsg(); 
	do 
	{
		Instructions();
		cout << "Enter Command: "; cin >> addRemoveClearPrint;
		
		Command(addRemoveClearPrint);

	} while ( !quit );

	delete queue;

	cout << "\n\n....Good Bye\n" << endl;
	system("pause");
	return 0;
}

//Decide on which command to trigger
void Command(char input)
{
	if ( input == 'A' || input == 'a' ) { AddToQueue();
	} 
	else if ( input == 'R' || input == 'r' ) { RemoveFromQueue();
	}
	else if ( input == 'C' || input == 'c' ) { ClearQueue();
	}
	else if ( input == 'p' || input == 'p' ) { PrintQueue();
	}
	else if ( input == 'q' || input == 'Q' ) { quit = true;
	}
}


//Add an element to Queue 
void AddToQueue()
{
	bool success = false;

	cout << "Enter a string: "; cin >> input;
	success = queue->Enqueue(input);

	cout << "\n >>>> RESULTS: <<<<" << endl; 
	cout << "======================================\n" << endl;
	if ( success ) 
	{ 
		cout << ">>> '" << input << "' - Successfully added to Queue <<<\n\n" << endl;
	} 
	else { cout << ">>> '" << input << "' - Error: Queue is Full. Cannot add anymore elements <<<\n\n" << endl; }
	
}


//Remove an element from Queue
void RemoveFromQueue()
{ 
	bool success = queue->Dequeue(output);

	cout << "\n >>>> RESULTS: <<<<" << endl; 
	cout << "======================================\n" << endl;
	if ( success ) 
	{ 
		cout << ">>> '" << output << "' - Successfully removed from Queue <<<\n\n\n" << endl;
	} 
	else { cout << ">>> Error: Queue is Empty. No elements to remove <<<\n\n\n" << endl; }
}


//Delete all elements in Queue
void ClearQueue()
{
	cout << "\n >>>> RESULTS: <<<<" << endl; 
	cout << "======================================\n" << endl;
	if ( !queue->isEmpty() ) 
	{ 
		queue->Clear();
		cout << ">>> Result: All elements from Queue deleted <<<\n\n\n" << endl;
	} 
	else { cout << ">>> Result: Queue is Empty, nothing to delete <<<\n\n\n" << endl; }
}


//Print the data in Queue
void PrintQueue() { queue->Print(); }


//Welcome Message
void WelcomeMsg()
{
	cout << "\n**************************************************" << endl;
	cout << "\t GSP295 Week 2: iLab Assignments" << endl;
	cout << "\n\t Title: FIFO Queue - Program 1" << endl;
	cout << "\n\t Author: Ronald Ram" << endl;
	cout << "**************************************************\n\n\n" << endl;
}



//Instructions for Command keys to use
void Instructions()
{
	cout << "---------------------------------------" << endl;
	cout << "Command Options: " << endl;
	cout << "---------------------------------------" << endl;
	cout << "Add[A] - Remove[R] - Clear[C] - Print[P]" << endl;
	cout << "Q -> Quit" << endl;
	cout << "---------------------------------------\n" << endl;
}